package cn.chinaunicom.admin.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.easy.secret.utils.SecureUtils;

import cn.chinaunicom.admin.entity.Fields;
import cn.chinaunicom.admin.service.IFieldsService;
import cn.chinaunicom.fast.common.utils.Result;
import lombok.extern.slf4j.Slf4j;

/**
 * @ProjectName: esay-secret-server
 * @Package: cn.chinaunicom.admin.controller
 * @ClassName: FieldsController
 * @Description: java类作用描述
 * @Author: wangjc
 * @CreateDate: 2023/11/20
 * @UpdateUser: wangjc
 * @UpdateDate: 2023/11/20
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("fields")
public class FieldsController {

    @Autowired
    private IFieldsService fieldsService;

//    @Lazy
//    @Autowired
    private SecureUtils secureUtils;

    @PostMapping("save")
    public Result save(@RequestBody Fields fields) {
        return Result.success(fieldsService.saveFields(fields));
    }

    @PostMapping("update")
    public Result update(@RequestBody Fields fields) {
        return Result.success(fieldsService.updateFields(fields));
    }

    @GetMapping("listAll")
    public Result list(){
        return Result.success(fieldsService.list());
    }

    /**
     * 批量修改
     *
     * @return
     */
    @GetMapping("batchUpd")
    public Result batchUpdate() {
        return Result.success(fieldsService.batchUpd());
    }

    @GetMapping("del")
    public Result remove(Integer id ){
        return Result.success(fieldsService.remove(new LambdaQueryWrapper<Fields>().eq(Fields::getCuserId, id)));
    }

    /**
     * test
     * @param str
     * @return
     */
    @GetMapping("test")
    public Result test(String str){
        String encrypt = secureUtils.encrypt(str);
        log.debug("str encrypt: " + encrypt);
        log.debug("decrypt str: " + secureUtils.decrypt(encrypt));
        log.debug("now date decrypt str: " + secureUtils.encryptDate(new Date()));
        return Result.success(encrypt);
    }
}
